const app = getApp()
import utils from "../../utils/index";
import {
  userModel,
  fansModel
} from "../../apis/index"

import regeneratorRuntime from '../../libs/wxPromise.min';

Page({
  data: {
    gradeList: [],
    page1: {
      page: 1,
      pageSize: 20
    },
    myFans: [],
  },
  mixins: [require('../../myMixin.js')],
  async onLoad(options) {
    let {uid = ''} = options
    if(!uid){
      utils.showToast('用户不存在','none')
      return
    }
  
    this.data.uid = uid
    let userInfo = await userModel.getUserInfo({uid})
    this.setData({
      userInfo,
    })
    getApp().setWatcher(this)

  },
  onShow() {
    this.getMyFansList()
    this.getFansGrade()
  },
  viewClubDetail(e){
    let item = e.currentTarget.dataset.item
    utils.goUrl(`../supstar/index?fid=${item.id}`)
  },
  getMyFansList() {
    let {uid} = this.data
    let {
      page,
      pageSize
    } = this.data.page1
    let {
      myFans
    } = this.data
    let param = {
      page: page,
      pageSize: pageSize,
      uid
    }
    utils.showLoading()
    fansModel.myFans(param).then(res => {
      let _list = res.list
      myFans = myFans.concat(_list)
      this.computedPage('page1', res.total)
      this.setData({
        myFans: myFans
      })
      utils.hideAll()
    }).catch(() => {
      utils.hideAll()
    })
  },
  getFansGrade() {
    let {uid} = this.data
    fansModel.fansGrade({uid}).then(res => {
      this.setData({
        gradeList: res
      })
    })
  },
  goUrl(e) {
    let url = e.currentTarget.dataset.url
    utils.goUrl(url)
  },
  watch: {

  },
})